﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CSharpDevTools.Views;
using HandyControl.Controls;
using HandyControl.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace CSharpDevTools.ViewModels
{
    internal class MainWindowViewModel : ObservableObject
    {
        private UserControl childControl = new HomeControl();

        public UserControl ChildControl
        {
            get => this.childControl;
            set => this.SetProperty(ref childControl, value);
        }

        public RelayCommand<FunctionEventArgs<object>> SwitchItemCmd => new(SwitchItem);

        private void SwitchItem(FunctionEventArgs<object>? info)
        {
            SideMenuItem? sideMenuItem = info?.Info as SideMenuItem;
            if (sideMenuItem != null && sideMenuItem.Tag != null)
            {
                Type? controlType = Type.GetType(sideMenuItem.Tag.ToString());
                if (controlType != null)
                {
                    this.ChildControl = Activator.CreateInstance(controlType) as UserControl;
                }
            }
        }
    }
}
